package engine.video.palette;

import engine.Constants;

public class PaletteMap {
	public PaletteMap() {
		_Data = new byte[Constants.PALETTE_ENTRIES];
	}
	public PaletteMap(byte[] data) {
		if (data == null) {
			_Data = new byte[Constants.PALETTE_ENTRIES];
		} else {
			_Data = data.clone(); // Create a copy of the data set.
		}
		_Data[0] = 0;
		if(_Data.length >= 256) {
			_Data[0xFF] = (byte)0xFF;
		}
	}
	public void setEntry(int from, byte to) {
		if (from < 0 || from >= _Data.length) {
			throw new ArrayIndexOutOfBoundsException();
		}
		if(from == 0 || from == _Data.length - 1) {
			return;
		}
		_Data[from] = to;
	}
	public byte getEntry(int from) {
		if (from < 0 || from >= _Data.length) {
			throw new ArrayIndexOutOfBoundsException();
		}
		return _Data[from];
	}
	public byte[] getEntries() {
		return _Data;
	}
	private byte[] _Data;
}
